package com.gavin.mybatis.mapper;

import com.gavin.mybatis.model.UserInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Mapper
public interface UserInfoMapper {

//    @Results(id = "BaseMap",value = {
//            @Result(column = "delete_flag",property = "deleteFlag"),
//            @Result(column = "create_time",property = "createTime"),
//            @Result(column = "update_time",property = "updateTime")
//    })
    @Select("select * from user_info")
    List<UserInfo> selectAll();

//    @RequestMapping(value = "BaseMap")
    @Select("select * from user_info where id =#{id}")
    UserInfo selectAById(Integer id);

    @Select("select * from user_info where id =#{id}")
    List<UserInfo> selectAById2(Integer id);

    @Select("select * from user_info where username=#{Username} and password=#{password}")
    List<UserInfo> selectByNameAndPassword(@Param("Username") String username,@Param("password") String password);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info(username,`password`,age)VALUES(#{username},#{password},#{age})")
    Integer insertUser(UserInfo userInfo);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info(username,`password`,age)" +
            "VALUES(#{userInfo.username},#{userInfo.password},#{userInfo.age})")
    Integer insertUser2(@Param("userInfo") UserInfo userInfo);

    @Delete("delete from user_info where id=#{id}")
    Integer deleteUser(Integer id);

    @Update("update user_info set delete_flag= #{deleteFlag} , phone = #{phone} where id = #{id}")
    Integer updateUser(UserInfo userInfo);

    @Select("select * from user_info order by id ${order}")
    List<UserInfo>  selectUserInfoOrder(String order);

    @Select("select * from user_info where username like CONCAT('%',#{userName},'%')")
    List<UserInfo> selectUserInfoLike(String userName);
}
